home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6839 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: silver.sdsmt.edu!not-for-mail
  2. From: kbs3387@silver.sdsmt.edu (Kevin Stone)
  3. Newsgroups: comp.lang.c,comp.graphics.algorithms,rec.games.programmer
  4. Subject: Re: Speed question here...
  5. Followup-To: comp.lang.c,comp.graphics.algorithms,rec.games.programmer
  6. Date: 15 Feb 1996 17:59:07 GMT
  7. Organization: South Dakota School of Mines and Technology
  8. Distribution: world
  9. Message-ID: <4fvs9b$s4l@news.sdsmt.edu>
  10. References: <4ftluh$1gkv@hearst.cac.psu.edu>
  11. NNTP-Posting-Host: silver.sdsmt.edu
  12. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  13.  
  14. : I was curious as to how fast something like the 
  15. : following would execute:
  16. :     int x;
  17. :     node *ptr;   ptr in linked list
  18. :        for ( ptr = first_node; ptr != NULL; ptr = ptr.next ) {
  19. :        for ( x = 0; x < max; x++ ) {
  20. :         array[x] = array_other[x];
  21. :            }
  22. :       } 
  23. : I really am not interested in the assignment statement, that's easy.
  24. : but the traversal through the linked list, and inner integer incremental
  25. : for loop for each node visited.  How fast is a traversal through
  26. : a linked list when you do a for loop at each node?
  27.  
  28.    The time complexity for this code is O(nodes * max), which could 
  29.    almost be stated as O(n^2).
  30.  
  31.    Speed is such a subjective issue.  Code alone won't tell you crap 
  32.    about how fast it will execute, apart from determining time 
  33.    complexities.  
  34.  
  35.    You should state what computer and what compiler your using, since both 
  36.    play a vital role.
  37.  
  38. BAS
  39.  
  40.